package com.azt.data.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.azt.data.utils.CommonUtil;
import com.azt.provider.mapper.ProjectMapper;
import com.azt.provider.mapper.UserMapper;
import com.xiaoleilu.hutool.util.StrUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * Created by timzou on 2017/11/23.
 */
@Controller
@RequestMapping("/stdProduct")
public class StdProductAction extends BaseAction{

    @Autowired
    private UserMapper userMapper;


    @Autowired
    private ProjectMapper projectMapper;


    @RequestMapping("/category")
    public String pieChartWithCategory() {
        return "stdProduct/categoryPie";
    }


    @RequestMapping("/getCategoryPie")
    @ResponseBody
    public JSONObject categoryPie(String startDate , String endDate , Integer source) {
        JSONObject json = new JSONObject();
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        if (StrUtil.isBlank(startDate)) {
            endDate = sdf.format(c.getTime());
            c.add(Calendar.MONTH, -11);
            startDate = sdf.format(c.getTime());
        }

        List<Map<String, Object>> data = projectMapper.selectStdCategoryPie(startDate, endDate, source);
        json.put("data", data);
        json.put("startDate", startDate);
        json.put("endDate", endDate);

        return json;
    }

    @RequestMapping("/getAreaPie")
    @ResponseBody
    public JSONObject AreaPie(String startDate , String endDate , Integer source) {
        JSONObject json = new JSONObject();
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        if (StrUtil.isBlank(startDate)) {
            endDate = sdf.format(c.getTime());
            c.add(Calendar.MONTH, -11);
            startDate = sdf.format(c.getTime());
        }

        List<Map<String, Object>> data = projectMapper.selectStdAreaPie(startDate, endDate, source);
        json.put("data", data);
        json.put("startDate", startDate);
        json.put("endDate", endDate);

        return json;
    }


    @RequestMapping("/area")
    public String pieChartWithArea() {


        return "stdProduct/areaPie";
    }

}
